#!/bin/bash
#coding:utf-8

# 第一步：安装相关依赖包

sudo dnf update -y
sudo dnf install python-wstool python-rosdep ninja-build -y


# 第二步：创建并初始化 名为 catkin_ws 的工作空间
mkdir -p /home/${USER}/ros/catkin_ws/
cd /home/${USER}/ros/catkin_ws/
wstool init src

# 第三步：生成编译所需依赖包
wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_turtlebot/master/cartographer_turtlebot.rosinstall
# vim src/.rosinstall
# 更改ceres-solver中地址改为下面的地址：
# uri: https://github.com/ceres-solver/ceres-solver.git
cp -f /home/${USER}/ros/fedora29roscartographer/installation_cartographer/src/.rosinstall /home/${USER}/ros/catkin_ws/src/.rosinstall
wstool update -t src

# 第四步：安装第三步中的包文件中的所需ros依赖
sudo cp -f /home/${USER}/ros/fedora29roscartographer/installation_ros/base-openeuler.yaml /etc/ros/rosdep/base-openeuler.yaml
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y -r

# 修改CMake文件，否则catkin_make_isolated会出现兼容性错误
cp -f /home/${USER}/ros/fedora29roscartographer/installation_cartographer/src/FindGMock.cmake /home/${USER}/ros/catkin_ws/src/cartographer/cmake/modules/FindGMock.cmake

# 第五步：编译安装
catkin_make_isolated --install --use-ninja -j1 --ignore-pkg cartographer_rviz
source install_isolated/setup.bash
